//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Reflection;
using System.Collections.Generic;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;
using EntLibContrib.Resource.Configuration.Manageability.Tests.Adm;

namespace EntLibContrib.Resource.Configuration.Manageability.Tests
{
	/// <summary>
	/// This wrapper allows unit tests to invoke the protected methods implemented by manageability providers.
	/// </summary>
	public class ConfigurationElementManageabilityProviderWrapper
	{
		private ConfigurationElementManageabilityProvider wrappedProvider;

		public ConfigurationElementManageabilityProviderWrapper(ConfigurationElementManageabilityProvider wrappedProvider)
		{
			this.wrappedProvider = wrappedProvider;
		}

		protected internal void AddAdministrativeTemplateDirectives(AdmContentBuilder contentBuilder,
			ConfigurationElement configurationObject,
			IConfigurationSource configurationSource,
			String parentKey)
		{
			MethodInfo addAdministrativeTemplateDirectivesMethodInfo = this.wrappedProvider.GetType().GetMethod("AddAdministrativeTemplateDirectives", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
			addAdministrativeTemplateDirectivesMethodInfo.Invoke(this.wrappedProvider, new object[] {contentBuilder,
			  configurationObject,
			  configurationSource,
			  parentKey});
		}

		public void InvokeAddAdministrativeTemplateDirectives(AdmContentBuilder contentBuilder,
			ConfigurationElement configurationObject,
			IConfigurationSource configurationSource,
			String parentKey)
		{
			this.AddAdministrativeTemplateDirectives(contentBuilder,
				configurationObject,
				configurationSource,
				parentKey);
		}

		protected internal bool OverrideWithGroupPoliciesAndGenerateWmiObjects(ConfigurationElement configurationObject,
			bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey,
			bool generateWmiObjects, ICollection<ConfigurationSetting> wmiSettings)
		{
			MethodInfo overrideWithGroupPoliciesAndGenerateWmiObjectsMethodInfo = this.wrappedProvider.GetType().GetMethod("OverrideWithGroupPoliciesAndGenerateWmiObjects", BindingFlags.Instance | BindingFlags.NonPublic);
			return (bool)overrideWithGroupPoliciesAndGenerateWmiObjectsMethodInfo.Invoke(this.wrappedProvider, new object[] {configurationObject,
				readGroupPolicies, machineKey, userKey,
				generateWmiObjects, wmiSettings});
		}
			
		public bool InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(ConfigurationElement configurationObject,
			bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey,
			bool generateWmiObjects, ICollection<ConfigurationSetting> wmiSettings)
		{
			return this.OverrideWithGroupPoliciesAndGenerateWmiObjects(configurationObject,
				readGroupPolicies, machineKey, userKey,
				generateWmiObjects, wmiSettings);
		}
	}
}
